﻿function Remove-DirectoriesFromTextFile {
    param (
        [Parameter(Mandatory=$true)]
        [string]$FilePath
    )

    try {
        # 检查文件是否存在
        if (-Not (Test-Path -Path $FilePath)) {
            throw "The file at path '$FilePath' does not exist."
        }

        # 读取文本文件中的每一行
        $directories = Get-Content -Path $FilePath

        foreach ($dir in $directories) {
            # 确保目录路径不是空的或只包含空白字符
            if ([string]::IsNullOrWhiteSpace($dir)) {
                continue
            }

            # 检查目录是否存在
            if (Test-Path -Path $dir -PathType Container) {
                Write-Output "Deleting directory: $dir"
                
                # 删除目录及其所有内容，包括子文件夹和文件
                Remove-Item -Path $dir -Recurse -Force
                
                Write-Output "Directory deleted successfully."
            } else {
                Write-Warning "The directory '$dir' does not exist or is not a valid directory."
            }
        }
    } catch {
        Write-Error "An error occurred while processing the directories: $_"
    }
}

# 示例调用函数
Remove-DirectoriesFromTextFile -FilePath "E:\output\deletedat.txt"